#!/usr/bin/env bash

# Examples from https://hpc-uit.readthedocs.io/en/latest/jobs/examples.html#job-script-examples

# Things you should definitely change:
#### Name
#### Number of CPUs you want/need
#### Your email address

# Give your job a name and enter your email address for status updates

#SBATCH --job-name=SS_JPEM
#SBATCH --mail-type=ALL
#SBATCH --mail-user=dempsey.164@osu.edu
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --cpus-per-task=40
#SBATCH --time=3-00:00:00
#SBATCH --mem-per-cpu=1000MB


export OMP_NUM_THREADS=${SLURM_CPUS_PER_TASK}

# Define and create a unique scratch directory for this job
SCRATCH_DIRECTORY=~/Z${SLURM_JOBID}
mkdir -p ${SCRATCH_DIRECTORY}
cd ${SCRATCH_DIRECTORY}

# You can copy everything you need to the scratch directory
# ${SLURM_SUBMIT_DIR} points to the path where this script was submitted from
cp -R ${SLURM_SUBMIT_DIR} ${SCRATCH_DIRECTORY}
cd ${SCRATCH_DIRECTORY}/Final_Replication

module load intel/2024.2.0
ifx kind_mod.f90 -c
ifx misc_utilities.f90 -c
ifx SS_JPEM_Module.f90 -c -qopenmp -qmkl
ifx kind_mod.o misc_utilities.o SS_JPEM_Module.o SS_JPEM_Main.f90 -o SS_JPEM -qopenmp -qmkl -fp-model source -O3 -noalign -cpp -auto

./SS_JPEM

cd ~/
cp -R ${SCRATCH_DIRECTORY}/Final_Replication/output scratch/SS_JPEM_Final_${SLURM_JOBID}
rm -r ${SCRATCH_DIRECTORY}

exit 0
